home *** CD-ROM | disk | FTP | other *** search
/ PC User 2003 September / Australian PC User - September 2003 (CD1).iso / magstuff / web / files / dwmx61.exe / Disk1 / data1.cab / Configuration_En / Commands / ServerObject-FormCmnPHP.js < prev    next >
Encoding:
JavaScript  |  2002-11-25  |  47.7 KB  |  1,664 lines

  1. // Copyright 2000 Macromedia, Inc. All rights reserved.
  2.  
  3.     
  4. //**********************GLOBAL VARS********************
  5.  
  6. // intialize labels
  7. var TEXTFIELD     =  MM.LABEL_TextField;
  8. var HIDDENFIELD   =  MM.LABEL_HiddenField;
  9. var PASSWORDFIELD =  MM.LABEL_PasswordField;
  10. var PASSWORD      =  MM.LABEL_Password;
  11. var FILEFIELD     =  MM.LABEL_FileField;
  12. var TEXTAREA      =  MM.LABEL_TextArea;
  13. var MENU          =  MM.LABEL_Menu;
  14. var CHECKBOX      =  MM.LABEL_CheckBox;
  15. var RADIOGROUP    =  MM.LABEL_RadioGroup;
  16. var STATICTEXT    =  MM.LABEL_Text;
  17.  
  18. var TEXT          =  "',none,none";
  19. var NUMERIC       =  "none,0,NULL";
  20. var DATE          =  "',none,NULL";
  21. var CHECKBOXYN    =  "none,Y,N";
  22. var CHECKBOX10    =  "none,1,0";
  23. var CHECKBOXNEG10 =  "none,-1,0";
  24. var DOUBLE        =  "none,.,NULL";
  25.  
  26. var STR_DIVIDER = "* *";
  27. var STR_ELEMENT_NAMES = STR_DIVIDER;
  28.  
  29. var DB_UNSUPPORTED_COLUMNS_ENUM_MAP = null;
  30.  
  31. //--------------------------------------------------------------------
  32. // FUNCTION:
  33. //   createFormElementStrings
  34. //
  35. // DESCRIPTION:
  36. //   This function creates the form element strings that will be used
  37. //   to create the final form.
  38. //
  39. // ARGUMENTS:
  40. //   none
  41. //
  42. // RETURNS:
  43. //   nothing
  44. //--------------------------------------------------------------------
  45. function createFormElementStrings(rowInfoArr)
  46. {
  47.   var nRows = rowInfoArr.length, i,currRowInfoObj;
  48.   var fieldInfoObj, fieldType, fieldLabel, fieldVal;
  49.   var formElemObj, formElemStrArr = new Array(), formElemStr;
  50.  
  51.   for (i = 0; i < nRows; i++)
  52.   {
  53.     fieldType = "", fieldLabel = "";
  54.     
  55.     currRowInfoObj = rowInfoArr[i];
  56.     fieldInfoObj = currRowInfoObj.displayAs; 
  57.     fieldInfoObj.fieldName = currRowInfoObj.fieldName;
  58.     fieldLabel = currRowInfoObj.label;    
  59.     fieldVal = fieldInfoObj.value;         
  60.     fieldType = fieldInfoObj.type;
  61.     
  62.     formElemObj = new Object();    
  63.     formElemObj.ElementName = fieldInfoObj.fieldName;
  64.     formElemObj.ElementType = fieldType.toLowerCase();
  65.     formElemObj.ElementValue = fieldVal;
  66.     formElemObj.ElementLabel = fieldLabel;
  67.     formElemObj.EqualToVal = "";
  68.     
  69.     if (fieldType == "checkBox")
  70.     {
  71.       formElemObj.ElementChecked = "";
  72.       if (fieldInfoObj.checked)
  73.       {
  74.         formElemObj.ElementChecked = "checked";
  75.       }
  76.     }
  77.     else if (fieldType == "text")
  78.     {
  79.       formElemObj.ElementValue = fieldInfoObj.text;
  80.     }
  81.     else if (fieldType == "dynamicCheckBox")
  82.     {  
  83.       formElemObj.ElementChecked = "";
  84.       if(fieldInfoObj.checkIf)
  85.       {
  86.         var selObj = new Object();
  87.         selObj.expression1 = dwscripts.encodeDynamicExpression(fieldInfoObj.checkIf); 
  88.         selObj.expression2 = dwscripts.encodeDynamicExpression(fieldInfoObj.equalTo); 
  89.         formElemObj.ElementChecked = extPart.getInsertString("", "dynamicCheckbox_attrib", selObj, "");
  90.       }
  91.     }
  92.     else if (fieldType == "menu")
  93.     {
  94.       var nOptions = fieldInfoObj.textArr.length;
  95.       var defaultSelected = fieldInfoObj.defaultSelected;
  96.       
  97.       if (!nOptions) 
  98.       {
  99.          var labelText = "[ " + MM.LABEL_Label + " ]";
  100.          fieldInfoObj.textArr = new Array(labelText, labelText);
  101.          fieldInfoObj.valArr   = new Array("menuitem1","menuitem2");
  102.          nOptions = 2;
  103.       }      
  104.       
  105.       formElemObj.OptionText = fieldInfoObj.textArr;
  106.       formElemObj.OptionValue = fieldInfoObj.valArr;
  107.  
  108.       var optionSelectedArr = new Array();
  109.       // This logic checks if the selected field is same as the value,
  110.       // if so marks it as selected, otherwise adds an empty string.
  111.       // this logic is required because all the arrays should be of same
  112.       // length for loop in edml file
  113.       for(var j = 0; j < nOptions; j++)
  114.       {
  115.         if(fieldInfoObj.valArr[j] && defaultSelected)
  116.         {
  117.           var selObj = new Object;
  118.           selObj.DefaultSelected = defaultSelected;
  119.           selObj.ItemValue = (fieldInfoObj.valArr[j])? dwscripts.encodeDynamicExpression(fieldInfoObj.valArr[j]):fieldInfoObj.valArr[j];
  120.           var expr = extPart.getInsertString("", "Menu_OptionSelected", selObj, "");
  121.           optionSelectedArr.push(expr);
  122.         }
  123.         else
  124.         {
  125.           optionSelectedArr.push("");
  126.         }
  127.       }
  128.       formElemObj.OptionSelected = optionSelectedArr;  
  129.     }
  130.     else if (fieldType == "dynamicMenu")
  131.     {
  132.       var equalTo = fieldInfoObj.defaultSelected;    
  133.       formElemObj.DynOptionText = fieldInfoObj.textCol;
  134.       formElemObj.DynOptionValue = fieldInfoObj.valCol;
  135.       formElemObj.EqualToVal = (equalTo)? dwscripts.encodeDynamicExpression(equalTo):equalTo; 
  136.       formElemObj.RecordsetName = fieldInfoObj.recordset;    
  137.     }
  138.     else if (fieldType == "radioGroup")
  139.     {
  140.       var nButtons = fieldInfoObj.labelArr.length;
  141.       var defaultChecked = fieldInfoObj.defaultChecked;
  142.       
  143.       if (!nButtons) 
  144.       {
  145.          var labelText = "[ " + MM.LABEL_Label + " ]";
  146.          fieldInfoObj.labelArr = new Array(labelText, labelText);
  147.          fieldInfoObj.valArr   = new Array("radiobutton1","radiobutton2");
  148.          nButtons = 2;
  149.       }
  150.       
  151.       formElemObj.FieldLabel = fieldInfoObj.labelArr;
  152.       formElemObj.FieldValue = fieldInfoObj.valArr;
  153.     
  154.       var fieldCheckedArr = new Array();
  155.       
  156.       // This logic checks if the checked field is same as the value,
  157.       // if so marks it as checked, otherwise adds an empty string.
  158.       // this logic is required because all the arrays should be of same
  159.       // length for a loop in edml file
  160.       for(j = 0;j < nButtons; j++)
  161.       {
  162.         if(fieldInfoObj.valArr[j] && defaultChecked)
  163.         {
  164.           var selObj = new Object;
  165.           selObj.DefaultChecked = dwscripts.encodeDynamicExpression(defaultChecked);
  166.           selObj.ItemValue = dwscripts.encodeDynamicExpression(fieldInfoObj.valArr[j]);
  167.           var expr = extPart.getInsertString("", "Radio_OptionChecked", selObj, "");
  168.           fieldCheckedArr.push(expr);
  169.         }
  170.         else
  171.         {
  172.           fieldCheckedArr.push("");
  173.         }
  174.       }
  175.       formElemObj.FieldChecked = fieldCheckedArr;       
  176.     }
  177.     else if (fieldType == "dynamicRadioGroup")
  178.     {
  179.       var equalTo = fieldInfoObj.defaultChecked;        
  180.       formElemObj.DynFieldName = fieldInfoObj.labelCol;
  181.       formElemObj.DynFieldValue = fieldInfoObj.valCol;
  182.       formElemObj.EqualToVal = (equalTo)? dwscripts.encodeDynamicExpression(equalTo):equalTo;
  183.       formElemObj.RecordsetName = fieldInfoObj.recordset;     
  184.     }
  185.     
  186.     
  187.     formElemStr = extPart.getInsertString("", "EditOp-FormElement", formElemObj, "");
  188.     formElemStrArr.push(formElemStr);
  189.   }
  190.   
  191.   return formElemStrArr;
  192. }
  193.  
  194.  
  195. //*-------------------------------------------------------------------
  196. // FUNCTION:
  197. //   wrapNamesWithSpaces
  198. //
  199. // DESCRIPTION:
  200. //   this fn is needed for SQL statements,
  201. //   names with spaces need brackets around them
  202. //
  203. // ARGUMENTS:
  204. //   nameStr - the name to wrap
  205. //
  206. // RETURNS:
  207. //   string - the wrapped name
  208. //--------------------------------------------------------------------
  209. function wrapNamesWithSpaces(nameStr){
  210.   var hasSpaces = ( nameStr.indexOf(" ") != -1 );
  211.   return (hasSpaces)? "[" + nameStr + "]" : nameStr;
  212.  
  213. }
  214.  
  215.  
  216. //*-------------------------------------------------------------------
  217. // FUNCTION:
  218. //   browseFile
  219. //
  220. // DESCRIPTION:
  221. //  Invokes dialog to allow user to select filename. Puts value in text input.
  222. //  The optional flag stripParameters will remove anything after a question
  223. //  mark if it is set to true
  224. //
  225. // ARGUMENTS:
  226. //   fieldToStoreURL 
  227. //   stripParameters - boolean flag to remove anything after a question
  228. //   mark
  229. //
  230. // RETURNS:
  231. //   string - the wrapped name
  232. //--------------------------------------------------------------------
  233. function browseFile(fieldToStoreURL, stripParameters) {
  234.   var fileName = "";
  235.   fileName = browseForFileURL();  //returns a local filename
  236.   if (stripParameters) {
  237.     var index = fileName.indexOf("?");
  238.     if (index != -1) {
  239.       fileName = fileName.substring(0,index);
  240.     }
  241.   }
  242.   if (fileName) fieldToStoreURL.value = fileName;
  243. }
  244.  
  245.  
  246. //--------------------------------------------------------------------
  247. // FUNCTION:
  248. //   populateColumnGrid
  249. //
  250. // DESCRIPTION:
  251. //   This function is called by updateUI function.  It is responsible
  252. //   for populating the Column grid.
  253. //
  254. // ARGUMENTS:
  255. //   none
  256. //
  257. // RETURNS:
  258. //   nothing
  259. //--------------------------------------------------------------------
  260. function populateColumnGrid()
  261. {
  262.   // clear additional column list
  263.   // it lists columns that don't get populated in the grid, and needs to be cleared
  264.   updateAdditionalColumnList('clear'); 
  265.     
  266.     // if there are no tables, then clear grid
  267.   if ( !connectionHasBeenChosen() )
  268.   {
  269.     _ColumnNames.setAllRows(new Array(),new Array());
  270.     return;
  271.   }
  272.  
  273.   var colsAndTypes = MMDB.getColumnAndTypeOfTable(_ConnectionName.getValue(), _TableName.getValue());
  274.   ColumnTypes = new Array();  // clear the column types map
  275.   var rowTextArr = new Array();
  276.   var rowValArr  = new Array();
  277.  
  278.   for (var i=0; i < colsAndTypes.length; i+=2)
  279.   {
  280.     ColumnTypes[colsAndTypes[i]] = colsAndTypes[i+1];
  281.     
  282.     if (EDIT_OP_TYPE == "Update") 
  283.     {
  284.       rowInfo = getRowTextAndValue(colsAndTypes[i], colsAndTypes[i+1], _RecordsetName.getValue(), _UniqueKeyColumn.getValue());
  285.     } 
  286.     else 
  287.     {  
  288.       // if Insert (and recordset menu does not exist)
  289.       rowInfo = getRowTextAndValue(colsAndTypes[i],colsAndTypes[i+1]);
  290.     }
  291.     rowTextArr.push(rowInfo[0]);
  292.     rowValArr.push(rowInfo[1]);
  293.   }
  294.  
  295.   _ColumnNames.setAllRows(rowTextArr, rowValArr);
  296.     
  297.   // clear global field names array (used to check for dupe field names)
  298.   STR_ELEMENT_NAMES = STR_DIVIDER;    
  299. }
  300.  
  301. //--------------------------------------------------------------------
  302. // FUNCTION:
  303. //   checkForUnsupportedColumnTypes
  304. //
  305. // DESCRIPTION:
  306. //   This function checks if all the columns are supported or not,
  307. //   displaying a message
  308. //
  309. // ARGUMENTS:
  310. //   Boolean - to display alert message or not
  311. //
  312. // RETURNS:
  313. //   Nothing
  314. //--------------------------------------------------------------------
  315. function checkForUnsupportedColumnTypes(displayMsg)
  316. {   
  317.   // check for the colTypes to make sure we support them, if not
  318.   // the flow is that they don't appear in the form fields grids,
  319.   // But we do display a message saying that they are not displayed,
  320.   // but the user can add them manually by clicking on the + button...
  321.   var unsupportedColTypes = new Array();
  322.   var unsupportedColNames = new Array();
  323.   
  324.   for(var i = 0; i < _ColumnNames.valueList.length; i++)
  325.   {
  326.     var rowInfoObj = _ColumnNames.valueList[i];
  327.     if (rowInfoObj && rowInfoObj.colType)
  328.     {
  329.       if (!isColTypeSupported(rowInfoObj.colType))
  330.       {
  331.         unsupportedColTypes.push(rowInfoObj.colType);
  332.         unsupportedColNames.push(rowInfoObj);
  333.       }
  334.     }
  335.   }  
  336.   
  337.   if (unsupportedColTypes.length && unsupportedColNames.length)
  338.   {
  339.     if(displayMsg)
  340.       alert(dwscripts.sprintf(MM.Msg_UnsupportedColumnsInTable, unsupportedColTypes));
  341.     for(var i = 0; i < unsupportedColNames.length; i++)
  342.     {
  343.       // select the row that is to be deleted...
  344.       _ColumnNames.pickRowValue(unsupportedColNames[i]);
  345.       deleteGridRow();    
  346.     }
  347.   }
  348.  
  349. }
  350.  
  351. //--------------------------------------------------------------------
  352. // FUNCTION:
  353. //   isColTypeSupported
  354. //
  355. // DESCRIPTION:
  356. //   This function returns if the colType is supported by UD or not.
  357. //
  358. // ARGUMENTS:
  359. //   colType - string - column type for update
  360. //
  361. // RETURNS:
  362. //   boolean
  363. //--------------------------------------------------------------------
  364. function isColTypeSupported(colType)
  365. {
  366.   var retVal = true;
  367.   if (DB_UNSUPPORTED_COLUMNS_ENUM_MAP == null)
  368.   {
  369.     buildUnsupportedColumnsEnum();
  370.   }
  371.   
  372.   var unsupportedCol = DB_UNSUPPORTED_COLUMNS_ENUM_MAP[colType.toLowerCase()]  
  373.   if (unsupportedCol)
  374.   {
  375.     // col is not supported,,,
  376.     retVal = false;
  377.   }
  378.   else
  379.   {
  380.     retVal = true;
  381.   }   
  382.   
  383.   return retVal;  
  384. }
  385.  
  386. //--------------------------------------------------------------------
  387. // FUNCTION:
  388. //   buildUnsupportedColumnsEnum
  389. //
  390. // DESCRIPTION:
  391. //   This function returns if the colType is supported by UD or not.
  392. //
  393. // ARGUMENTS:
  394. //   colType - string - column type for update
  395. //
  396. // RETURNS:
  397. //   boolean
  398. //--------------------------------------------------------------------
  399. function buildUnsupportedColumnsEnum()
  400. {
  401.     if (DB_UNSUPPORTED_COLUMNS_ENUM_MAP == null)
  402.     {
  403.       // TODO: read in from a configuration file
  404.       var a = new Array();
  405.       a["binary"] = 128; 
  406.       a["varbinary"] = 204;
  407.       a["longvarbinary"] = 204; 
  408.       a["longbinary"] = 205; // matched to longvarbinary
  409.                 
  410.       //oracle
  411.       a["raw"]  = 204;// Match it to Binary
  412.       a["nclob"]  = 204;//Match it to Binary
  413.       a["bfile"]  = 204;//Match it to Binary
  414.       a["ref cursor"] = 900; //Arbitrary ID Val
  415.       a["refcursor"] = 900;
  416.       // SQL Server 7
  417.       a["image"]  =  204 ;// binary
  418.       
  419.       DB_UNSUPPORTED_COLUMNS_ENUM_MAP = a;
  420.     }
  421. }
  422.  
  423.  
  424. //--------------------------------------------------------------------
  425. // FUNCTION:
  426. //   getRowTextAndValue
  427. //
  428. // DESCRIPTION:
  429. //   This function returns the information for a row in the column table.
  430. //
  431. // ARGUMENTS:
  432. //   colName - string - column name
  433. //   colType - string - column type
  434. //   rsName  - string - (optional) recordset name, only needed for update
  435. //   uniqueColName - string - (optional) Unique Key Column, only needed
  436. //                            for update
  437. //
  438. // RETURNS:
  439. //   array of 2 values
  440. //--------------------------------------------------------------------
  441. function getRowTextAndValue(colName, colType, rsName, uniqueColName)
  442. {
  443.   var retVal = new Array(2);
  444.   var colFieldType = "", colSubmitType = "", colSubmitName = "";
  445.   
  446.   var colLabel = getLabelFromColumnName(colName);
  447.   
  448.   var fieldName = getElementNameFromColumnName(colName);
  449.   // if update, the unique key column should be a static text...
  450.   if (EDIT_OP_TYPE == "Update" && colName == uniqueColName)
  451.   {
  452.     colFieldType = STATICTEXT;
  453.   }
  454.   else
  455.   {
  456.     // default to password display type if "password" appears in field name
  457.     if (colName.toLowerCase().indexOf(PASSWORD) != -1)
  458.     {
  459.       colFieldType = PASSWORDFIELD;
  460.     }
  461.     else
  462.     {
  463.       colFieldType = getFieldTypeFromColumnType(colType);
  464.     }
  465.   }
  466.   
  467.   var colSubmitType = getSubmitTypeFromColumnType(colType);
  468.   var colSubmitName = getSubmitNameFromSubmitType(colSubmitType);   
  469.  
  470.   var colDisplayAs = getFormFieldStorageObjectFromFormFieldType(colFieldType);
  471.   
  472.   // disable the _SubmitAs field if it is for the Primary Key column
  473.   if (EDIT_OP_TYPE == "Update" && colName == uniqueColName)
  474.   {
  475.     UniqueColSubmitAs = colSubmitType;
  476.     colSubmitType = "";  
  477.     colSubmitName = "";
  478.     toggleSubmitAs(false); // enable or disable Submit As Menu
  479.     toggleLabelVisibility(colDisplayAs);    // enable or disable Label textfield
  480.   }
  481.   
  482.   var rowText = colName + "|" + colLabel + "|" + colFieldType + "|" + colSubmitName;
  483.  
  484.   var rowValObj = new Object();  
  485.   rowValObj.column = colName;
  486.   rowValObj.label = colLabel;
  487.   rowValObj.displayAs = colDisplayAs;
  488.   rowValObj.submitAs = colSubmitType;
  489.   rowValObj.fieldName = fieldName;
  490.   rowValObj.defaultStr = "";
  491.   rowValObj.passwordStr = "";
  492.   rowValObj.colType = colType;
  493.   
  494.   // populate storage object with any default values
  495.   if (EDIT_OP_TYPE == "Update" && rowValObj.displayAs.type != "passwordField")
  496.   {
  497.     var rs = (rsName)?rsName:_RecordsetName.getValue();
  498.     rowValObj = populateFormFieldStorageType(rowValObj,rs,colName);
  499.   }
  500.  
  501.   retVal[0] = rowText;
  502.   retVal[1] = rowValObj;
  503.             
  504.   return retVal;
  505. }
  506.  
  507. //--------------------------------------------------------------------
  508. // FUNCTION:
  509. //   getLabelFromColumnName
  510. //
  511. // DESCRIPTION:
  512. //
  513. // ARGUMENTS:
  514. //
  515. // RETURNS:
  516. //   Nothing
  517. //--------------------------------------------------------------------
  518. function getLabelFromColumnName(colName)
  519. {
  520.   return colName.charAt(0).toUpperCase() + colName.substring(1) + MM.LABEL_Delimiter;      
  521. }
  522.  
  523. //--------------------------------------------------------------------
  524. // FUNCTION:
  525. //   getElementNameFromColumnName
  526. //
  527. // DESCRIPTION:
  528. //
  529. // ARGUMENTS:
  530. //   col - string - the column name to create an element name from
  531. //
  532. // RETURNS:
  533. //   string -  the element name
  534. //--------------------------------------------------------------------
  535. function getElementNameFromColumnName(col)
  536. {
  537.   var elemName = col;
  538.   var counter = 2;
  539.   var divider = STR_DIVIDER;
  540.  
  541.   // replace spaces with underscores
  542.   elemName = elemName.replace(/ /g, "_");
  543.   
  544.   // strip out all characters that are not alpha-numeric, or underscores
  545.   elemName = elemName.replace(/[^a-zA-Z_0-9]/g, "");
  546.   
  547.   // don't allow the first character to be numeric
  548.   while (parseInt(elemName.charAt(0)) &&
  549.          parseInt(elemName.charAt(0)) == elemName.charAt(0) )
  550.   {
  551.     elemName = elemName.substring(1);
  552.   }
  553.  
  554.   // in the unlikely case that no characters are left after the above,
  555.   // then name element generically as "element"
  556.   if (elemName.length == 0)
  557.   {
  558.     elemName = MM.LABEL_Element;
  559.   }
  560.  
  561.   // ensure that name is not a dupe
  562.   var tempName = elemName; 
  563.   while (STR_ELEMENT_NAMES.indexOf(divider + elemName + divider) != -1)
  564.   {
  565.     elemName = tempName + counter++;
  566.   }
  567.  
  568.   // add name to global names list
  569.   STR_ELEMENT_NAMES += elemName + divider;
  570.  
  571.   return elemName;
  572. }
  573.  
  574. //--------------------------------------------------------------------
  575. // FUNCTION:
  576. //   getFieldTypeFromColumnType
  577. //
  578. // DESCRIPTION:
  579. //   This function returns the field type based on the given column type
  580. //
  581. // ARGUMENTS:
  582. //   colType - string - the column type returned from MMDB
  583. //
  584. // RETURNS:
  585. //   Nothing
  586. //--------------------------------------------------------------------
  587. function getFieldTypeFromColumnType(colType)
  588. {
  589.   return (dwscripts.isBooleanDBColumnType(colType)) ? CHECKBOX : TEXTFIELD;
  590. }
  591.  
  592. //--------------------------------------------------------------------
  593. // FUNCTION:
  594. //   getSubmitTypeFromColumnType
  595. //
  596. // DESCRIPTION:
  597. //   This function is called when the grid is populated, to choose a 
  598. //   submit type based on the column type
  599. //
  600. //   Note: this function is used during initial population only.
  601. //         getSubmitTypeBasedOnElementType() is used when the 
  602. //         element type is changed
  603. //
  604. // ARGUMENTS:
  605. //   colType - string - the column type returned from MMDB
  606. //
  607. // RETURNS:
  608. //   nothing
  609. //--------------------------------------------------------------------
  610. function getSubmitTypeFromColumnType(colType)
  611. {
  612.   var retVal = "";
  613.   var colIsDouble = dwscripts.isDoubleDBColumnType(colType);
  614.   var colIsNumeric = dwscripts.isNumericDBColumnType(colType);
  615.   var colIsDate    = dwscripts.isDateDBColumnType(colType);
  616.   var colIsBoolean = dwscripts.isBooleanDBColumnType(colType);
  617.   // added condition for currency...skarra
  618.   var colIsCurrency = dwscripts.isCurrencyDBColumnType(colType);
  619.  
  620.   if ( colIsDouble )
  621.   {
  622.       retVal = DOUBLE;
  623.   }
  624.   else if ( colIsNumeric )
  625.   {
  626.     retVal = (colIsBoolean) ? CHECKBOX10 : NUMERIC;
  627.   }
  628.   else if ( colIsDate )
  629.   {
  630.     retVal = DATE;
  631.   }
  632.   else if (colIsCurrency)
  633.   {
  634.     retVal = NUMERIC;
  635.   }
  636.   else
  637.   { // if text-based
  638.     retVal = (colIsBoolean) ? CHECKBOXYN : TEXT;
  639.   }
  640.   
  641.   return retVal;
  642. }
  643.  
  644. //--------------------------------------------------------------------
  645. // FUNCTION:
  646. //   getSubmitTypeBasedOnElementType
  647. //
  648. // DESCRIPTION:
  649. //   Called when the element type is changed, to update the submit type
  650. //
  651. // ARGUMENTS:
  652. //   submitType - string - the current submit type
  653. //   elemType - string - the current element type
  654. //   colType - string - the current column type
  655. //
  656. // RETURNS:
  657. //   Nothing
  658. //--------------------------------------------------------------------
  659. function getSubmitTypeBasedOnElementType(submitType, elemType, colType)
  660. {
  661.   var newSubmitType = submitType;
  662.   
  663.   // don't bother if conection hasn't been chosen
  664.   if ( connectionHasBeenChosen() )
  665.   {
  666.     var colIsNumeric = dwscripts.isNumericDBColumnType(colType);
  667.     var colIsDate    = dwscripts.isDateDBColumnType(colType);
  668.  
  669.     if ( elemType == CHECKBOX )
  670.     { 
  671.       // if display element is a checkbox
  672.       if (colIsNumeric)
  673.       {
  674.         newSubmitType = CHECKBOX10;
  675.       }
  676.       else
  677.       {
  678.         newSubmitType = CHECKBOXYN;
  679.       }
  680.     }
  681.     else
  682.     { // display type does not equal checkbox
  683.  
  684.       // if submit type is currently a checkbox type,
  685.       // then change it back to the most appropriate
  686.       // non-checkbox type
  687.  
  688.       if (submitType==CHECKBOXYN    || submitType==CHECKBOX10 ||
  689.           submitType==CHECKBOXNEG10)
  690.       {
  691.         if (colIsNumeric)
  692.         {
  693.           newSubmitType = NUMERIC;
  694.         }
  695.         else if (colIsDate)
  696.         {
  697.           newSubmitType = DATE;
  698.         }
  699.         else
  700.         {
  701.           newSubmitType = TEXT;
  702.         }
  703.       }
  704.     }
  705.   }
  706.   
  707.   return newSubmitType;
  708. }
  709.  
  710.  
  711. //--------------------------------------------------------------------
  712. // FUNCTION:
  713. //   getSubmitNameFromSubmitType
  714. //
  715. // DESCRIPTION:
  716. //   Returns the display string that should be used for the given
  717. //   submit as type
  718. //
  719. // ARGUMENTS:
  720. //   submitType - string - the comma separated list of submit values
  721. //
  722. // RETURNS:
  723. //   string
  724. //--------------------------------------------------------------------
  725. function getSubmitNameFromSubmitType(submitType)
  726. {
  727.   var submitTypeLabels = _SubmitAs.get('all');
  728.   var submitTypeValues = _SubmitAs.getValue('all');
  729.   
  730.   var submitName = "";
  731.   
  732.   var index = dwscripts.findInArray(submitTypeValues, submitType);
  733.   if (index >= 0)
  734.   {
  735.     submitName = submitTypeLabels[index];
  736.   }
  737.   else
  738.   {
  739.     submitName = submitTypeLabels[0];
  740.   }
  741.   
  742.   return submitName;
  743. }
  744.  
  745. //--------------------------------------------------------------------
  746. // FUNCTION:
  747. //   getFormFieldStorageObjectFromFormFieldType
  748. //
  749. // DESCRIPTION:
  750. //   This function returns a field storage object, based on the 
  751. //   given field type.
  752. //
  753. // ARGUMENTS:
  754. //   fieldType - string - the field type selected in the UI
  755. //
  756. // RETURNS:
  757. //   object
  758. //--------------------------------------------------------------------
  759. function getFormFieldStorageObjectFromFormFieldType(fieldType)
  760. {
  761.   var retObj = "";
  762.  
  763.   if (fieldType == STATICTEXT)
  764.   {
  765.     retObj = new eoText();
  766.   }
  767.   else if (fieldType == TEXTFIELD)
  768.   {
  769.     retObj = new eoTextField();
  770.   }
  771.   else if (fieldType == HIDDENFIELD)
  772.   {
  773.     retObj = new eoHiddenField();
  774.   }
  775.   else if (fieldType == PASSWORDFIELD)
  776.   {
  777.     retObj = new eoPasswordField();
  778.   }
  779.   else if (fieldType == FILEFIELD)
  780.   {
  781.     retObj = new eoFileField();
  782.   }
  783.   else if (fieldType == TEXTAREA)
  784.   {
  785.     retObj = new eoTextArea();
  786.   }
  787.   else if (fieldType == MENU)
  788.   {
  789.     retObj = new eoMenu();
  790.   }
  791.   else if (fieldType == RADIOGROUP)
  792.   {
  793.     retObj = new eoRadioGroup();
  794.   }
  795.   else if (fieldType == CHECKBOX)
  796.   {
  797.     retObj = (EDIT_OP_TYPE == "Insert")?new eoCheckBox():new eoDynamicCheckBox();
  798.   } 
  799.  
  800.   return retObj;
  801. }
  802.  
  803. //--------------------------------------------------------------------
  804. // FUNCTION:
  805. //   displayGridFieldValues
  806. //
  807. // DESCRIPTION:
  808. //   This function is called when the user clicks on a new row in the 
  809. //   grid, changes the values of the UI fields to display the correct
  810. //   information
  811. //
  812. // ARGUMENTS:
  813. //   None
  814. //
  815. // RETURNS:
  816. //   Nothing
  817. //--------------------------------------------------------------------
  818. function displayGridFieldValues()
  819.   // don't bother if grid is empty -- needed because this fn is also
  820.   // called when the connection or table changes
  821.   if (_ColumnNames.list.length == 0)
  822.   {
  823.     _ElementLabel.value = "";
  824.   }
  825.   else
  826.   {
  827.     var currRowText = _ColumnNames.getRow();
  828.     var currRowVal  = _ColumnNames.getRowValue();
  829.     
  830.     var rowTextTokens = getTokens(currRowText,"|");
  831.  
  832.     // TODO: this should be taken from the record, not the display
  833.     _ElementLabel.value = rowTextTokens[1]; // update label field
  834.     _DisplayAs.pickValue(rowTextTokens[2]); // update display menu
  835.  
  836.     // change UI at bottom of dialog, if relevent
  837.     // for instance, if prior row had displayAs = Text, but this row has displayAs = Menu
  838.     showDifferentParams(); 
  839.  
  840.     if (dwscripts.findDOMObject("SubmitAs")) 
  841.     {
  842.       _SubmitAs.pickValue(currRowVal.submitAs); // update submit menu
  843.     }
  844.  
  845.     // fill in form parameters at bottom of UI
  846.     // note that in the case of radio or menu, there is nothing to fill in
  847.     switch (currRowVal.displayAs.type)
  848.     {
  849.     case "text":
  850.       dwscripts.findDOMObject("Text").value = currRowVal.displayAs.text = currRowVal.defaultStr;
  851.       break;
  852.     case "textArea":
  853.     case "textField":
  854.     case "hiddenField":
  855.     case "fileField":
  856.       dwscripts.findDOMObject("SetValueTo").value = currRowVal.displayAs.value = currRowVal.defaultStr;
  857.       break;
  858.     case "passwordField":
  859.       dwscripts.findDOMObject("SetValueTo").value = currRowVal.displayAs.value = currRowVal.passwordStr;
  860.       break;
  861.     case "checkBox": 
  862.       // note: dwscripts.findDOMObject doesn't work with radios, so manual references are needed
  863.       var InitialStateRadios = document.forms[0].InitialState;
  864.       if ( currRowVal.displayAs.checked.toString() == "true")
  865.       {
  866.         InitialStateRadios[0].checked = true; InitialStateRadios[1].checked = false;
  867.       }
  868.       else
  869.       {
  870.         InitialStateRadios[0].checked = false; InitialStateRadios[1].checked = true;
  871.       }
  872.       break;
  873.  
  874.     case "dynamicCheckBox":
  875.       dwscripts.findDOMObject("CheckIf").value = currRowVal.displayAs.checkIf;
  876.       dwscripts.findDOMObject("EqualTo").value = currRowVal.displayAs.equalTo;
  877.       break;
  878.  
  879.     case "default":
  880.       break; 
  881.     }
  882.  
  883.     _ColumnNames.setRowIndex(_ColumnNames.getRowIndex());
  884.   }
  885. }
  886.  
  887. //--------------------------------------------------------------------
  888. // FUNCTION:
  889. //   showDifferentParams
  890. //
  891. // DESCRIPTION:
  892. //   This function shows form field specific parameters at the bottom
  893. //   of the dialog for instance, shows "Menu Properties" button for 
  894. //   menu, value field for textfield, etc
  895. //
  896. // ARGUMENTS:
  897. //   displayDefaultStr - Column Name
  898. //
  899. // RETURNS:
  900. //   Nothing
  901. //--------------------------------------------------------------------
  902. function showDifferentParams(displayDefaultStr)
  903. {
  904.   // don't bother if connection has not been chosen
  905.   if ( connectionHasBeenChosen() )
  906.   {
  907.     //EnableDisableUpDownBtns();
  908.     
  909.     //EnableDisableAddDelBtns();
  910.     
  911.     var displayAs = _DisplayAs.getValue()?_DisplayAs.getValue():"none";
  912.     var tables = domUIPieces.getElementsByTagName("TABLE"), param, i;
  913.     var mmParamsTag = document.getElementsByTagName("mmParams").item(0);
  914.  
  915.     var rowInfoObj = _ColumnNames.getRowValue();
  916.     if (EDIT_OP_TYPE == "Update" && rowInfoObj.fieldName == _UniqueKeyColumn.getValue())
  917.     {
  918.       toggleSubmitAs(false);
  919.     }
  920.     else
  921.     {
  922.       toggleSubmitAsVisibility(displayAs); // enable or disable Submit As Menu
  923.       toggleLabelVisibility(displayAs);    // enable or disable Label textfield
  924.     }
  925.  
  926.     if (displayAs == TEXTFIELD || displayAs == TEXTAREA || displayAs == HIDDENFIELD ||
  927.       displayAs == PASSWORDFIELD || displayAs == FILEFIELD)
  928.     {
  929.       param = "textField";
  930.     }
  931.     else if (displayAs == STATICTEXT)
  932.     {
  933.       param = "text";
  934.     }
  935.     else if (displayAs == RADIOGROUP)
  936.     {
  937.       param = "radio";
  938.     }
  939.     else if (displayAs == MENU)
  940.     {
  941.       param = "menu";
  942.     }
  943.     else if (displayAs == CHECKBOX)
  944.     {
  945.       param = (EDIT_OP_TYPE == "Insert") ? "checkBox" : "dynamicCheckBox";
  946.     }
  947.     else if (displayAs == "none")
  948.     {
  949.       param = "none";
  950.     }
  951.  
  952.     for (i=0;i<tables.length;i++)
  953.     {
  954.       if (tables[i].name && tables[i].name == param)
  955.       {
  956.         mmParamsTag.innerHTML = tables[i].innerHTML;
  957.         break;
  958.       }
  959.     }
  960.     // if display as equals text, text area, or text field, and the display as menu has
  961.     // just been changed, then display the default text for this column
  962.     if (displayDefaultStr)
  963.     {
  964.       var rowInfoObj = _ColumnNames.getRowValue();
  965.       var defaultStr = _ColumnNames.getRowValue().defaultStr;
  966.       var passwordStr = _ColumnNames.getRowValue().passwordStr;
  967.       if ( displayAs == TEXTFIELD || displayAs == TEXTAREA ||
  968.         displayAs == HIDDENFIELD || displayAs == FILEFIELD )
  969.       {
  970.         dwscripts.findDOMObject("SetValueTo").value = rowInfoObj.displayAs.value = defaultStr;  // set UI
  971.       }
  972.       else if ( displayAs == PASSWORDFIELD )
  973.       {
  974.         dwscripts.findDOMObject("SetValueTo").value = rowInfoObj.displayAs.value = passwordStr;    // set UI
  975.       }
  976.       else if ( displayAs == STATICTEXT )
  977.       {
  978.         dwscripts.findDOMObject("Text").value = rowInfoObj.displayAs.text = defaultStr;    // set UI
  979.       }
  980.       else if ( param == "dynamicCheckBox" )
  981.       {
  982.         dwscripts.findDOMObject("CheckIf").value = rowInfoObj.displayAs.checkIf = defaultStr;
  983.       }
  984.     }
  985.   }
  986. }
  987.  
  988. //--------------------------------------------------------------------
  989. // FUNCTION:
  990. //   addGridRow
  991. //
  992. // DESCRIPTION:
  993. //   This function is called if there are columns not already 
  994. //   displayed in the grid pop up the "Add Columns" dialog, and allow
  995. //   the user to add them
  996. //
  997. // ARGUMENTS:
  998. //   None
  999. //
  1000. // RETURNS:
  1001. //   Nothing
  1002. //--------------------------------------------------------------------
  1003. function addGridRow()
  1004. {
  1005.   // check to see if there are columns to add first
  1006.   if (ColumnsToAdd.length == 0)
  1007.   {
  1008.     alert(MM.MSG_NoMoreColumnsToAdd);
  1009.     return;
  1010.   }
  1011.   var addedCols = dwscripts.callCommand("Add Column.htm", ColumnsToAdd);
  1012.   if (!addedCols) return; // user clicked Cancel
  1013.   var nCols = addedCols.length,i, currCol, rowInfoArr;
  1014.  
  1015.   for (i=0;i<nCols;i++)
  1016.   {
  1017.     currCol = addedCols[i];
  1018.     rowInfoArr = getRowTextAndValue(currCol,ColumnTypes[currCol]);
  1019.     _ColumnNames.addRow(rowInfoArr[0],rowInfoArr[1]);
  1020.     updateAdditionalColumnList('del',currCol);
  1021.   }
  1022. }
  1023.  
  1024. //--------------------------------------------------------------------
  1025. // FUNCTION:
  1026. //   deleteGridRow
  1027. //
  1028. // DESCRIPTION:
  1029. //   This function is called when the user clicks the "-" image button
  1030. //
  1031. // ARGUMENTS:
  1032. //  None
  1033. //
  1034. // RETURNS:
  1035. //   Nothing
  1036. //--------------------------------------------------------------------
  1037. function deleteGridRow()
  1038. {
  1039.   var currRow = _ColumnNames.getRow();
  1040.   var currCol = currRow.substring(0,currRow.indexOf("|") );
  1041.   var nRows = _ColumnNames.list.length;
  1042.  
  1043.   if (nRows > 1)
  1044.   {
  1045.     updateAdditionalColumnList('add',currCol);
  1046.     _ColumnNames.delRow();
  1047.     displayGridFieldValues(); 
  1048.   }
  1049.   else
  1050.   {
  1051.     alert(MM.MSG_NeedOneColumnInList);
  1052.   }
  1053. }
  1054.  
  1055. //--------------------------------------------------------------------
  1056. // FUNCTION:
  1057. //   updateGridRow
  1058. //
  1059. // DESCRIPTION:
  1060. //   This function is called whenever the label, submitAs, or displayAs
  1061. //   fields are edited updates both the actual text display in the grid, 
  1062. //   and the object that stores the information about the display
  1063. //
  1064. // ARGUMENTS:
  1065. //   whichColumn: the parameter which has been edited -- displayAs, 
  1066. //   submitAs, or label
  1067. //
  1068. // RETURNS:
  1069. //   Nothing
  1070. //--------------------------------------------------------------------
  1071. function updateGridRow(whichColumn)
  1072. {
  1073.   // check that connection has been chosen before proceeding
  1074.   if ( !connectionHasBeenChosen() )
  1075.   {
  1076.     alert( MM.MSG_NoDataSourceSelected );
  1077.     // _DisplayAs.setIndex(0); // set display menu back to first item
  1078.     return;
  1079.   }
  1080.  
  1081.   var currRowObj  = _ColumnNames.getRowValue();
  1082.   var currRowText = _ColumnNames.getRow();
  1083.   var currColName = currRowText.substring(  0,currRowText.indexOf("|")  );
  1084.  
  1085.   // update grid row text
  1086.   var newRowText = currColName + "|" + _ElementLabel.value + "|" + _DisplayAs.get() + "|"; 
  1087.   newRowText += (dwscripts.findDOMObject("SubmitAs")) ? _SubmitAs.get() : "";
  1088.   _ColumnNames.setRow(newRowText);
  1089.  
  1090.   // update object that stores information about grid row
  1091.   // this object is stored in a value attribute of the Grid object
  1092.   // these objects are stored in an array: GridObj.valueList
  1093.  
  1094.   switch (whichColumn)
  1095.   {
  1096.   case "label":
  1097.     currRowObj.label = _ElementLabel.value;
  1098.     break;
  1099.  
  1100.   case "submitAs":
  1101.     currRowObj.submitAs = _SubmitAs.getValue();
  1102.     break;
  1103.  
  1104.   case "displayAs": 
  1105.     currRowObj.displayAs = getFormFieldStorageObjectFromFormFieldType(_DisplayAs.getValue());
  1106.     // need to update submit property, because changing displayAs menu can
  1107.     // auto-change submit type
  1108.     if ( dwscripts.findDOMObject("SubmitAs") )
  1109.     {
  1110.       currRowObj.submitAs = _SubmitAs.getValue();
  1111.     }
  1112.  
  1113.     var defaultStr = currRowObj.defaultStr;
  1114.     var passwordStr = currRowObj.passwordStr;
  1115.     var fieldType = currRowObj.displayAs.type;
  1116.  
  1117.     if ( fieldType == "textField"  || fieldType == "hiddenField" || 
  1118.       fieldType == "fileField"  ||  fieldType == "textArea" )
  1119.     {
  1120.       currRowObj.displayAs.value = defaultStr;
  1121.     }
  1122.     else if ( fieldType == "passwordField")
  1123.     {
  1124.       currRowObj.displayAs.value = passwordStr;          
  1125.     }
  1126.     else if ( fieldType == "text")
  1127.     {
  1128.       currRowObj.displayAs.text = defaultStr;
  1129.     }
  1130.     else if ( fieldType == "menu")
  1131.     {
  1132.       currRowObj.displayAs.defaultSelected = defaultStr;
  1133.     }
  1134.     else if ( fieldType == "radioGroup")
  1135.     {
  1136.       currRowObj.displayAs.defaultChecked = defaultStr;
  1137.     }
  1138.     else if (fieldType == "dynamicCheckBox")
  1139.     {
  1140.       currRowObj.displayAs.checkIf = defaultStr;
  1141.     }
  1142.     break;
  1143.  
  1144.   default:
  1145.     break;
  1146.   }
  1147. }
  1148.  
  1149. //--------------------------------------------------------------------
  1150. // FUNCTION:
  1151. //   popUpFormFieldPropertiesDialog
  1152. //
  1153. // DESCRIPTION:
  1154. //   It pops up the Radio or Menu Properties dialog, and passes in the 
  1155. //   current menu/radio storage object so that the dialog can be 
  1156. //   initialized correctly
  1157. //
  1158. // ARGUMENTS:
  1159. //   whichOne - String that can be "Radio" or "Menu"
  1160. //
  1161. // RETURNS:
  1162. //   Nothing
  1163. //--------------------------------------------------------------------
  1164. function popUpFormFieldPropertiesDialog(whichOne)
  1165. {
  1166.   var commandFileName = "ServerObject-" + whichOne + "Props.htm";
  1167.   var rowObj = _ColumnNames.getRowValue();
  1168.   var fieldInfoObj = dwscripts.callCommand(commandFileName,rowObj.displayAs)
  1169.  
  1170.  
  1171.   // note: use the "type" property on the menuInfoObj to see which
  1172.     // type of object was returned
  1173.     if (fieldInfoObj)
  1174.   {
  1175.     rowObj.displayAs = fieldInfoObj;
  1176.   }
  1177. }
  1178.  
  1179. //--------------------------------------------------------------------
  1180. // FUNCTION:
  1181. //   updateAdditionalColumnList
  1182. //
  1183. // DESCRIPTION:
  1184. //   The + button calls up an Add Columns dialog, allowing
  1185. //   the user to add additional columns to the list. When the Add Columns
  1186. //   dialog is called, it is populated with the "additional columns list".
  1187. //   This list is updated when a user adds or deletes a column from the UI.
  1188. //
  1189. // ARGUMENTS:
  1190. //   action - Action argument that can Add, Del or Clear
  1191. //   col    - Column
  1192. //
  1193. // RETURNS:
  1194. //   Nothing
  1195. //--------------------------------------------------------------------
  1196. function updateAdditionalColumnList(action, col)
  1197. {
  1198.   if (action == 'add')
  1199.   {
  1200.     ColumnsToAdd.push(col);
  1201.   }
  1202.   else if ( action == 'clear')
  1203.   {
  1204.     ColumnsToAdd = new Array();
  1205.   }
  1206.   else
  1207.   { // delete an item from additional column list
  1208.     for (var i=0; i < ColumnsToAdd.length; i++)
  1209.     {
  1210.       if (ColumnsToAdd[i] == col)
  1211.       {
  1212.         ColumnsToAdd.splice(i,1);
  1213.         break;
  1214.       }
  1215.     }
  1216.   }
  1217. }
  1218.  
  1219. //--------------------------------------------------------------------
  1220. // FUNCTION:
  1221. //   connectionHasBeenChosen
  1222. //
  1223. // DESCRIPTION:
  1224. //   This function is called when the grid is populated, to choose a 
  1225. //   submit type based on the column type
  1226. //
  1227. // ARGUMENTS:
  1228. //   None
  1229. //
  1230. // RETURNS:
  1231. //   Nothing
  1232. //--------------------------------------------------------------------
  1233. function connectionHasBeenChosen()
  1234. {
  1235.   return (_ConnectionName.getValue());
  1236. }
  1237.  
  1238. //--------------------------------------------------------------------
  1239. // FUNCTION:
  1240. //   checkThatCursorIsNotInsideOfAForm
  1241. //
  1242. // DESCRIPTION:
  1243. //   Before inserting a form, check that cursor is not inside of 
  1244. //   an existing form. If it is, set IP location to be just after the form
  1245. //
  1246. // ARGUMENTS:
  1247. //   None
  1248. //
  1249. // RETURNS:
  1250. //   Nothing
  1251. //--------------------------------------------------------------------
  1252. function checkThatCursorIsNotInsideOfAForm()
  1253. {
  1254.   var dom = dw.getDocumentDOM();
  1255.   var formNode = findForm(dom);
  1256.  
  1257.   if (formNode)
  1258.   { // if inside of a form tag
  1259.     formArr = dom.nodeToOffsets(formNode);
  1260.     dom.setSelection(formArr[1]+1,formArr[1]+1);
  1261.   }
  1262. }
  1263.  
  1264. //--------------------------------------------------------------------
  1265. // FUNCTION:
  1266. //   findForm
  1267. //
  1268. // DESCRIPTION:
  1269. //   Before inserting a form, check that cursor is not inside of 
  1270. //   an existing form. If it is, set IP location to be just after the form
  1271. //
  1272. // ARGUMENTS:
  1273. //   dom - DOM object
  1274. //
  1275. // RETURNS:
  1276. //   formObj
  1277. //--------------------------------------------------------------------
  1278. function findForm(dom)
  1279. {
  1280.   var formObj="";
  1281.   var selArr = dom.getSelection();
  1282.   var selObj = dom.offsetsToNode(selArr[0],selArr[1]);
  1283.  
  1284.   while (formObj=="" && selObj.parentNode)
  1285.   {
  1286.     if (selObj.nodeType == Node.ELEMENT_NODE && selObj.tagName=="FORM")
  1287.       formObj=selObj;
  1288.     else
  1289.       selObj = selObj.parentNode;
  1290.   }
  1291.  
  1292.   return formObj;
  1293. }
  1294.  
  1295. //--------------------------------------------------------------------
  1296. // FUNCTION:
  1297. //   toggleSubmitAsVisibility
  1298. //
  1299. // DESCRIPTION:
  1300. //   toggles the visibility of "Submit As: [menu]" that appears on 
  1301. //   the UI.  This menu should be visible for all items except text
  1302. //
  1303. // ARGUMENTS:
  1304. //   displayAs
  1305. //
  1306. // RETURNS:
  1307. //   Nothing
  1308. //--------------------------------------------------------------------
  1309. function toggleSubmitAsVisibility(displayAs)
  1310. {
  1311.   var currentVal = _SubmitAs.getValue();
  1312.   if ( displayAs != STATICTEXT && (currentVal == " " || !currentVal))
  1313.   { // if any form field is chosen in displayAs menu
  1314.     _SubmitAs.enable();
  1315.     _SubmitAs.del();
  1316.     var submitType = getSubmitTypeFromColumnType(ColumnTypes[_ColumnNames.getRowValue().column]);
  1317.     _SubmitAs.pickValue(submitType);
  1318.   }
  1319.   else if (displayAs == STATICTEXT)
  1320.   { // if plain text was chosen in displayAs menu
  1321.     _SubmitAs.append(" ");
  1322.     _SubmitAs.disable();
  1323.   }
  1324. }
  1325.  
  1326. //--------------------------------------------------------------------
  1327. // FUNCTION:
  1328. //   toggleLabelVisibility
  1329. //
  1330. // DESCRIPTION:
  1331. //   toggles the visibility of "Label: [textfield]" that appears on
  1332. //   the UI.  This textfield should be visible for all items except 
  1333. //   hidden fields
  1334. //
  1335. // ARGUMENTS:
  1336. //   displayAs
  1337. //
  1338. // RETURNS:
  1339. //   Nothing
  1340. //--------------------------------------------------------------------
  1341. function toggleLabelVisibility(displayAs)
  1342. {
  1343.   var labelFieldIsVisible = !( _ElementLabel.disabled == "true");
  1344.  
  1345.   if (displayAs != HIDDENFIELD && !labelFieldIsVisible)
  1346.   { // if non-hidden field & non-visible label field
  1347.     _ElementLabel.setAttribute("disabled","false")                     // then make label field visible
  1348.       _ElementLabel.setAttribute("value",_ColumnNames.getRowValue().label); // and set value of it 
  1349.  
  1350.   }
  1351.   else if (displayAs == HIDDENFIELD && labelFieldIsVisible)
  1352.   {  // if hidden field
  1353.     _ElementLabel.setAttribute("value","");                          // then set value field to empty string
  1354.     _ElementLabel.setAttribute("disabled","true");                   // and make it non-editable
  1355.   }
  1356. }
  1357.  
  1358. //--------------------------------------------------------------------
  1359. // FUNCTION:
  1360. //   toggleSubmitAs
  1361. //
  1362. // DESCRIPTION:
  1363. //   toggles the visibility of "Submit As: [menu]" that appears on 
  1364. //   the UI.  This menu is disabled in case of Update form and if
  1365. //   it is a primary key column
  1366. //
  1367. // ARGUMENTS:
  1368. //   show - boolean 
  1369. //
  1370. // RETURNS:
  1371. //   Nothing
  1372. //--------------------------------------------------------------------
  1373. function toggleSubmitAs(bShow)
  1374. {
  1375.   if (bShow)
  1376.   { 
  1377.     _SubmitAs.enabled();
  1378.   }
  1379.   else
  1380.   {
  1381.     _SubmitAs.append(" ");
  1382.     _SubmitAs.disable();
  1383.   }
  1384. }
  1385.  
  1386. //--------------------------------------------------------------------
  1387. // FUNCTION:
  1388. //   EnableDisableUpDownBtns
  1389. //
  1390. // DESCRIPTION:
  1391. //   Enable/disables the elemUp and elemDown buttons
  1392. //
  1393. // ARGUMENTS:
  1394. //   None
  1395. //
  1396. // RETURNS:
  1397. //   Nothing
  1398. //--------------------------------------------------------------------
  1399. function EnableDisableUpDownBtns()
  1400. {
  1401.   // Check if there are any columns
  1402.   if (_ColumnNames.list.length == 0 || _ColumnNames.getRowIndex() == -1)
  1403.   {
  1404.     _ElemUp.setAttribute("disabled", true);
  1405.     _ElemUp.src = "../Shared/MM/Images/btnUp_dis.gif";   
  1406.     
  1407.     _ElemDown.setAttribute("disabled", true);
  1408.     _ElemDown.src = "../Shared/MM/Images/btnDown_dis.gif";        
  1409.   }
  1410.   else
  1411.   {
  1412.     if(_ColumnNames.list.length == 1)
  1413.       {
  1414.       // first row, so disable the up and down buttons
  1415.       _ElemDown.setAttribute("disabled", true);
  1416.       _ElemDown.src = "../Shared/MM/Images/btnDown_dis.gif";
  1417.  
  1418.       _ElemUp.setAttribute("disabled", true);
  1419.       _ElemUp.src = "../Shared/MM/Images/btnUp_dis.gif";
  1420.     }  
  1421.     if(_ColumnNames.list.length-1 == _ColumnNames.getRowIndex())
  1422.     {
  1423.       // last row, so disable the down button and enable the up button
  1424.       _ElemDown.setAttribute("disabled", true);
  1425.       _ElemDown.src = "../Shared/MM/Images/btnDown_dis.gif";
  1426.             
  1427.       _ElemUp.setAttribute("disabled", false);
  1428.       _ElemUp.src = "../Shared/MM/Images/btnUp.gif";
  1429.     }
  1430.     // first row, if it is disable up button and enable the down button
  1431.     else if (_ColumnNames.getRowIndex() == 0)
  1432.     {
  1433.       _ElemUp.setAttribute("disabled", true);
  1434.       _ElemUp.src = "../Shared/MM/Images/btnUp_dis.gif";
  1435.       
  1436.       _ElemDown.setAttribute("disabled", false);
  1437.       _ElemDown.src = "../Shared/MM/Images/btnDown.gif";      
  1438.     }    
  1439.     else
  1440.     {
  1441.       //enable both up and down buttons
  1442.       _ElemDown.setAttribute("disabled", false);
  1443.       _ElemDown.src = "../Shared/MM/Images/btnDown.gif";
  1444.             
  1445.       _ElemUp.setAttribute("disabled", false);
  1446.       _ElemUp.src = "../Shared/MM/Images/btnUp.gif";      
  1447.     }
  1448.   }
  1449. }
  1450.  
  1451.  
  1452. //--------------------------------------------------------------------
  1453. // FUNCTION:
  1454. //   EnableDisableAddDelBtns
  1455. //
  1456. // DESCRIPTION:
  1457. //   Enable/disables the elemAdd and elemDel buttons
  1458. //
  1459. // ARGUMENTS:
  1460. //   None
  1461. //
  1462. // RETURNS:
  1463. //   Nothing
  1464. //--------------------------------------------------------------------
  1465. function EnableDisableAddDelBtns()
  1466. {
  1467.   // Check if there are any columns
  1468.   if (_ColumnNames.list.length == 0 || _ColumnNames.getRowIndex() == -1)
  1469.   {
  1470.     _ElemAdd.setAttribute("disabled", true);
  1471.     _ElemAdd.src = "../Shared/MM/Images/btnAdd_dis.gif";   
  1472.     
  1473.     _ElemDel.setAttribute("disabled", true);
  1474.     _ElemDel.src = "../Shared/MM/Images/btnDel_dis.gif";        
  1475.   }
  1476.   else
  1477.   {
  1478.     if (ColumnsToAdd.length == 0)
  1479.     {
  1480.       // no columns to add, so disable add button and enable delete button
  1481.       _ElemAdd.setAttribute("disabled", true);
  1482.       _ElemAdd.src = "../Shared/MM/Images/btnAdd_dis.gif"; 
  1483.       
  1484.       _ElemDel.setAttribute("disabled", false);
  1485.       _ElemDel.src = "../Shared/MM/Images/btnDel.gif";            
  1486.     }
  1487.     else
  1488.     {
  1489.       // enable both add and delete buttons
  1490.       _ElemAdd.setAttribute("disabled", false);
  1491.       _ElemAdd.src = "../Shared/MM/Images/btnAdd.gif"; 
  1492.     
  1493.       _ElemDel.setAttribute("disabled", false);
  1494.       _ElemDel.src = "../Shared/MM/Images/btnDel.gif";                
  1495.     }
  1496.   }
  1497. }
  1498.  
  1499. //--------------------------------------------------------------------
  1500. // FUNCTION:
  1501. //   displayDynamicDataDialog
  1502. //
  1503. // DESCRIPTION:
  1504. //   pops up the dialog allowing the user to choose dynamic data
  1505. //
  1506. // ARGUMENTS:
  1507. //   textFieldObj
  1508. //
  1509. // RETURNS:
  1510. //   Nothing
  1511. //--------------------------------------------------------------------
  1512. function displayDynamicDataDialog(textFieldObj)
  1513. {
  1514.   var serverModel = dw.getDocumentDOM().serverModel.getServerName();
  1515.   var expression = dw.showDynamicDataDialog(textFieldObj.value);
  1516.  
  1517.   if (expression)
  1518.   {
  1519. //    if (serverModel == "Cold Fusion")
  1520. //    {
  1521. //      expression = dwscripts.stripCFOutputTags(expression);
  1522. //    }
  1523.     textFieldObj.value = expression;
  1524.   }
  1525. }
  1526.  
  1527.  
  1528.  
  1529.  
  1530. //--------------------------------------------------------------------
  1531. // FUNCTION:
  1532. //   populateFormFieldStorageType
  1533. //
  1534. // DESCRIPTION:
  1535. //   This function is called by updateUI function.  It is responsible
  1536. //   for populating the Column grid.
  1537. //
  1538. // ARGUMENTS:
  1539. //   rowValObj - Column Name
  1540. //   rsName - Column Type
  1541. //   colName  - Recordset Name
  1542. //
  1543. // RETURNS:
  1544. //   Array
  1545. //--------------------------------------------------------------------
  1546. function populateFormFieldStorageType(rowValObj, rsName, colName)
  1547. {
  1548.   // note: this fn is only called when the row is first created, which is why
  1549.   // it only lists some of the available form types
  1550.   var displayType = rowValObj.displayAs.type;
  1551.   var dynDataVal = createDynamicData(rsName,colName);
  1552.   
  1553.   rowValObj.defaultStr = dynDataVal;
  1554.  
  1555.   if (displayType == "textField" || 
  1556.       displayType  == "textArea" || 
  1557.       displayType  == "hiddenField" )
  1558.   {
  1559.     rowValObj.displayAs.value = dynDataVal;
  1560.   }
  1561.   else if (displayType == "text" )
  1562.   {
  1563.     rowValObj.displayAs.text = dynDataVal;
  1564.   }
  1565.   else if (displayType == "dynamicCheckBox")
  1566.   {
  1567.     rowValObj.displayAs.checkIf = dynDataVal;
  1568.   }
  1569.  
  1570.   return rowValObj;
  1571. }
  1572.  
  1573.  
  1574. //--------------------------------------------------------------------
  1575. // FUNCTION:
  1576. //   createDynamicData
  1577. //
  1578. // DESCRIPTION:
  1579. //   Pops up the dialog allowing the user to choose dynamic data
  1580. //
  1581. // ARGUMENTS:
  1582. //   rs - Recordset
  1583. //   col - Column Name
  1584. //
  1585. // RETURNS:
  1586. //   String
  1587. //--------------------------------------------------------------------
  1588. function createDynamicData(rs,col)
  1589. {
  1590.   var retVal = "";
  1591.   if (rs){
  1592.     var colArray = dwscripts.getFieldNames(rs);
  1593.     if (dwscripts.findInArray(colArray, col) != -1){
  1594.       var paramObj = new Object();
  1595.       paramObj.sourceName = rs;
  1596.       paramObj.bindingName = col;
  1597.  
  1598.       retVal = extPart.getInsertString("", "Recordset_DataRef", paramObj);
  1599.     }
  1600.   }
  1601.   return retVal;
  1602. }
  1603.  
  1604.  
  1605. //--------------------------------------------------------------------
  1606. // FUNCTION:
  1607. //   updateDefaultFormFieldValues
  1608. //
  1609. // DESCRIPTION:
  1610. //   Goes through the default values, and replace references to the old
  1611. //   recordset with the new recordset
  1612. //
  1613. // ARGUMENTS:
  1614. //   oldRS - old Recordset
  1615. //   newRS - new Recordset
  1616. //
  1617. // RETURNS:
  1618. //   Nothing
  1619. //--------------------------------------------------------------------
  1620. function updateDefaultFormFieldValues(oldRS, newRS)
  1621. {
  1622.   var rowObjs = _ColumnNames.valueList;
  1623.   var nRows = rowObjs.length, i, fieldType, currRowObj, regExp;
  1624.  
  1625.   for (i=0;i<nRows;i++)
  1626.   {
  1627.     currRowObj = rowObjs[i];
  1628.     regExp = new RegExp(oldRS,"g");
  1629.     currRowObj.defaultStr = currRowObj.defaultStr.toString().replace(regExp,newRS);
  1630.     currRowObj.passwordStr = currRowObj.passwordStr.toString().replace(regExp,newRS);
  1631.  
  1632.     // update the current display
  1633.     switch(currRowObj.displayAs.type)
  1634.     {
  1635.       case "textField":
  1636.       case "textArea":
  1637.       case "hiddenField":
  1638.         currRowObj.displayAs.value = currRowObj.defaultStr;
  1639.         break;
  1640.       case "passwordField":
  1641.         currRowObj.passwordField.value = currRowObj.passwordStr;
  1642.         break;
  1643.       case "text":
  1644.         currRowObj.displayAs.text = currRowObj.defaultStr;
  1645.         break;
  1646.       case "radioGroup":
  1647.       case "dynamicRadioGroup":
  1648.         currRowObj.displayAs.defaultChecked = currRowObj.defaultStr;
  1649.         break;
  1650.       case "menu":
  1651.       case "dynamicMenu":
  1652.         currRowObj.displayAs.defaultSelected = currRowObj.defaultStr;
  1653.         break;
  1654.       case "dynamicCheckBox":
  1655.         currRowObj.displayAs.checkIf = currRowObj.defaultStr;
  1656.         break;
  1657.       case "default":
  1658.         break;  
  1659.     }
  1660.   } 
  1661.  
  1662. }
  1663.